<template>
  <el-dialog
      v-model="scmsAddWinDialogVisible"
      title="新增点检保养计划"
      width="60%"
      @close="handleClose"
      draggable
      center
  >
    <template #default>
      <el-form :model="newScms">
        <el-row>
          <el-form-item label="计划编码" style="margin-right: 100px">
            <el-input v-model="newScms.scmsEncode" style="width: 200px"/>
          </el-form-item>
          <el-form-item label="计划名称">
            <el-input v-model="newScms.scmsName" style="width: 200px"/>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="计划类型" style="margin-right: 100px">
            <el-select placeholder="请选择计划类型" style="width:150px" v-model="newScms.scmsType">
              <el-option label="设备点检计划" :value="1"/>
              <el-option label="设备保养计划" :value="2"/>
            </el-select>
          </el-form-item>
          <el-form-item label="频率">
            <el-input-number v-model="newScms.scmsFnum" :min="1"/>
            <el-select placeholder="请选择频率" style="width:150px" v-model="newScms.scmsFunit">
              <el-option label="小时" value="小时"/>
              <el-option label="天" value="天"/>
              <el-option label="周" value="周"/>
              <el-option label="月" value="月"/>
              <el-option label="季" value="季"/>
              <el-option label="年" value="年"/>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="开始日期">
            <el-date-picker
                v-model="newScms.scmsStart"
                value-format="YYYY-MM-DD"
            />
          </el-form-item>
          <el-form-item label="结束日期">
            <el-date-picker
                v-model="newScms.scmsEnd"
                value-format="YYYY-MM-DD"
            />
          </el-form-item>
          <el-form-item label="状态">
            <el-select placeholder="请选择状态" style="width:150px" v-model="newScms.scmsStatus">
              <el-option label="草稿" :value="1"/>
              <el-option label="已确认" :value="2"/>
              <el-option label="审批中" :value="3"/>
              <el-option label="已审批" :value="4"/>
              <el-option label="已完成" :value="5"/>
            </el-select>
          </el-form-item>
        </el-row>
        <el-form-item label="备注">
          <el-input type="textarea" v-model="newScms.scmsRemark"/>
        </el-form-item>
      </el-form>
    </template>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="addScmsSubmit">提交</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import {ref, watch} from "vue";
import scmsRequest from "@/api/scms.js";

let newScms = ref({scmsFnum : 1});
const props = defineProps(['flag']);
const emits = defineEmits(['cancelAdd','addComplete'])
let scmsAddWinDialogVisible = ref(false);


function handleClose(){
  newScms = ref({scmsFnum : 1});
  emits("cancelAdd");
}
function cancel(){
  newScms = ref({scmsFnum : 1});
  emits("cancelAdd");
}
/**
 * 新增点检项目的提交按钮事件
 */
function addScmsSubmit() {
  scmsRequest.insert(newScms.value, res => {
    emits("addComplete");
    scmsAddWinDialogVisible.value = false;
  })
}

// 属性侦听
watch(() => props.flag, () => {
  scmsAddWinDialogVisible.value = props.flag === 1;
});
</script>
<style scoped>

</style>